
class SlipPlugin:
	def __init__(self):
		# put all the links this plugins supports here - it will be used to filter supported URLs
		self.supported_sites = ['jimslip.com', 'www.beautyandthesenior.com']
		self.supported_urls = self.supported_sites

	def get(self, url):
		"""Get all the images from jimslip.com"""
		parsed_url = urlparse.urlparse(url)
		directory = parsed_url[2].split('/')[2]
		try: os.mkdir(os.path.join(config.dl_dir, directory))
		except: pass

		curr = 1
		while True:
			curr_url, local_file = self._gen_url(url, curr)
			parser = URLLister()
			parser.feed(urllib2.urlopen(curr_url).read())
		
			for img_url in parser.image_urls:
				my_url = img_url
				break

			parser.close()
			curr += 1
			download_file_with_retries(os.path.join(directory, local_file, my_url))
			config.report.report_finish(local_file)

	def url_matches(self, url):
		"""Check whether we support this URL"""
		for l in self.supported_urls:
			if url.find(l) != -1:
				return True
		return False

	def version(self):
		"""Return plugin version - when interface changes, the version changes"""
		return 1

	def _gen_url(self, url, number):
		"""Generate url for jimslip based on start url and number"""
		parsed_url = urlparse.urlparse(url)
		url_new = parsed_url[2].split('q/large/')[0].split('/p/')[0] + '/p/' + str(number) + '/q/large/index.html'
		fname = parsed_url[2].split('/')[2] + '_' + "%03d" % number + '.jpg'
		return (parsed_url[0] + '://' + parsed_url[1] + url_new, fname)

modules = [SlipPlugin()]
